﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Common.Activities.Contract;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace DWF.Studio.RemoteCtrls.ActivityToolBox.Node
{
    internal class CategoryNode : TreeNode
    {
        protected SortableObservableCollection<TreeNode> ChildNodes = null;

        public CategoryNode()
        {
            IsExisting = true;
            Visible = true;
            ChildNodes = new SortableObservableCollection<TreeNode>();
        }

        public CategoryNode(ToolBoxCategoryAttribute categoryAttribute)
            : this()
        {
            DisplayName = categoryAttribute.DisplayName;
            SortNo = categoryAttribute.CategorySort;
        }

        public override ObservableCollection<TreeNode> Children
        {
            get
            {
                return ChildNodes;
            }
        }

        public override ObservableCollection<TreeNode> SortChildren
        {
            get
            {
                Sort();
                return ChildNodes;
            }
        }

        public override void Sort()
        {
            var items = ChildNodes.OrderBy(item => item.IsLeaf).ThenBy(item => item.SortNo);
            ChildNodes.Sort(items);
        }
    }
}
